import Vue from 'vue'
import store from '@/store'

/**
 * 权限指令
 */
Vue.directive('permission', {
  bind: function (el, binding, vnode) {
    hasPermission(binding.value) || setTimeout(() => el.parentNode.removeChild(el))
    function hasPermission (value) {
      let perms = store.state.user.perms
      if (!perms || !perms.length) {
        return false
      }
      return perms.filter(perm => perm.code === value).length
    };
  }
})
